Convert an address into geographic coordinates¶
Convert an address (like “1600 amphitheatre parkway, mountain view, ca”)
into geographic coordinates (like latitude 37.423021 and longitude -122.083739).
Geocodin:
Geocoding is the process of converting addresses
(like “1600 Amphitheatre Parkway, Mountain View, CA”)
into geographic coordinates
(like latitude 37.423021 and longitude -122.083739),
which you can use to place markers on a map, or position the map.
import requests
geo_url = 'http://maps.googleapis.com/maps/api/geocode/json'
my_address = {'address': 'XXX Runnymede St,
Palo Alto,
California',
'language': 'en'}
response = requests.get(geo_url, params = my_address)
results = response.json()['results']
my_geo = results[0]['geometry']['location']
print("Longitude:", my_geo['lng'], "\n", "Latitude:", my_geo['lat'])
Output:
Longitude: 100.0000000
Latitude: 100.0000000